import { getMessageCount } from '@fl/api/man-api/message-center'
import { store } from '@fl/store/index'
import { defineStore } from 'pinia'

export const useMessageBadgeStore = defineStore('messageBadge', {
    actions: {
        async initBadge() {
            const data = await getMessageCount()
            this.badge = data > 99 ? '99+' : data
        },
        setBadge(val: number | string): void {
            this.badge = val ?? 0
        },
    },
    getters: {
        getBadge(): number {
            return this.badge
        },
    },
    persist: true,
    state: (): any => ({
        badge: 0,
    }),
})

export function useMessageBadgeStoreWithOut() {
    return useMessageBadgeStore(store)
}
